package com.ming.rabbitmq.three;

import com.ming.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.util.concurrent.TimeUnit;

public class Work04 {
    public static final String QUEUE_NAME="ack_queue";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            try {
                TimeUnit.SECONDS.sleep(30L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("work04接收到的消息："+new String(message.getBody()));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };

        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("消息消费被取消");
        };
        System.out.println("C4Worker正在等待接收消息：");
        channel.basicQos(5);
        TimeUnit.SECONDS.sleep(1L);

        channel.basicConsume(QUEUE_NAME, false, deliverCallback, cancelCallback);

    }

}
